﻿Imports MySql.Data.MySqlClient
Public Class frmedit_depot
    Dim mysql As MySqlConnection = main_form.mysqlconection
    Dim mySqlCommand As New MySqlCommand
    Dim mySqlAdaptor As New MySqlDataAdapter
    Dim mySqlReader As MySqlDataReader
    Dim respone As Object
    Dim idvoys As String
    Dim idvoyn As String
    Dim id_primary As String
    Private Sub ButtonX1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX1.Click
        mysql.Close()
        If mysql.State = ConnectionState.Closed Then
            mysql.Open()
        End If
        Try
            Dim commandText2 As String
            commandText2 = "UPDATE ctndepotunit SET  depotname = '" & txtcustomer.Text & "'  ,depotmanhr = '" & TextBox1.Text & "' WHERE idctndepotunit = " & frmsearch_codedepot.iddepot & "; "
            mySqlCommand.CommandText = commandText2
            mySqlCommand.CommandType = CommandType.Text
            mySqlCommand.Connection = mysql

            mySqlCommand.ExecuteNonQuery()
            mysql.Close()

            MsgBox("แก้ไขข้อเรียบร้อย")
            Dim cf As New frmsearch_codedepot

            cf.MdiParent = Me.MdiParent
            Me.Close()
            cf.Dock = DockStyle.Fill
            cf.Show()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

    End Sub

    Private Sub frmedit_depot_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US")
        System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture
        mysql.Close()
        If mysql.State = ConnectionState.Closed Then
            mysql.Open()
        End If
        mySqlCommand.CommandText = "Select * from ctndepotunit where idctndepotunit ='" & frmsearch_codedepot.iddepot & "' ;"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = mysql
        mySqlAdaptor.SelectCommand = mySqlCommand

        Try
            mySqlReader = mySqlCommand.ExecuteReader

            While (mySqlReader.Read())
              
                txtcustomer.Text = mySqlReader("depotname")


                If mySqlReader("depotmanhr") Is DBNull.Value Then

                Else
                    TextBox1.Text = mySqlReader("depotmanhr")

                End If

            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        mysql.Close()
    End Sub
End Class